<template>
	<div class="tpl23-header"   
   :style="tplItemData.modulePadding || tplItemData.modulePadding ==0?'padding-top:'+tplItemData.modulePadding+'px;padding-bottom:'+tplItemData.modulePadding+'px;':'padding-top:5px;padding-bottom:5px;'">
    <!-- 折叠轮播 -->
    <div ref="getHeight"  class="imgAdv-box">
      <!-- TODO 小程序端用swiper -->
      <wx-swiper  class="my-swipe" :style="`height: ${imgadvWxH}`" indicator-color="#ebedf0" indicator-active-color="#FE5000" :autoplay="autoplay" :indicator-dots="showIndicators">
        <wx-swiper-item v-for="(item,index) in tplItemData.dataset" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic" alt="" @load="onImageLoad($event)"/>
          </a>
        </wx-swiper-item>
      </wx-swiper>
    </div>
    <div class="search-container">
      <div class="search-wrapper">
        <div class="icon" @click="searchList">
          <!-- TODO svg换成图片 -->
          <img class="icon_search" src="https://img.wifenxiao.com/h5-wfx/images/common/search-icon.png" />
        </div>
        <input @confirm="searchList" v-model="keyword" type="text" :placeholder="tplItemData.has_duodian?'商品搜索：请输入商品、店铺名称':'商品搜索：请输入商品关键字'" />
      </div>  
    </div>
  </div>
</template>

<script>
  /**
   * @Author: yqe@360shop.cn
   * @Date: 2020年07月08日15:11:21
   * @Last Modified by: yqe@360shop.cn
   * @Last Modified time: 2020年07月08日15:11:21
   */
import Vue from 'vue'
import { openPage } from '@/utils/utils'
import { Swipe, SwipeItem } from 'vant'
Vue.use(Swipe)
Vue.use(SwipeItem)
export default Vue.extend({
    name: 'index',
    data() {
      return {
        imgadvWxH: '0',
        showIndicators: true,
        autoplay: true,
        keyword: ''
      }
    },
    props: {
      tplItemData: {
        type: Object // 传入参数的类型
      }
    },
    methods: {
      searchList() {
        this.$JumpName(this, 'item-list', { title: this.keyword })
      },
      // TODO 小程序跳转
      openLink(link) {
          openPage(link)
      },
      // TODO 小程序swiper获取图片高度
      onImageLoad(event){
        const imgHeight = event.detail.height
        if(imgHeight > parseFloat(this.imgadvWxH)){
          this.imgadvWxH = imgHeight+'px'
        }
      }
    },

    created() {
  
    }
  })
</script>

<style lang='scss'>
 @import "src/styles/mixin";
 .miniprogram-root {
   .search-wrapper .h5-input {
     margin-top: 0;
   }
 }
.tpl23-header{
  position: relative;
  .imgAdv-box{
    img{
      width: 100%;
    }
  }
  .search-container{
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    width: 100%;
    text-align: center;
    padding: 30px 0;
    .search-wrapper{
      position:relative;
      width: 90%;
      margin: 0 auto;
      height: 60px;
      line-height: 68px;
      border-radius: 30px;
      border: 1px solid #fff;
      background: rgba(255,255,255,.7);
      .icon {
        position:absolute;
        left:20px;
        top: 2px;
        // top:50%;
        // transform: translateY(-50%);
        color:#999999;
        font-size: 24px;
        margin-right: 10px;
        .icon_search{
          width:32px;
          height:32px;
        }
      }
      @include placeColor(#999);
      input {
        display: inline-block;
        width:100%;
        height: 60px;
        padding:15px 70px;
        border:0;
        background: transparent;
        box-sizing: border-box;
      }
    }
  }
  
}

</style>
